package com.zhou.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhou.entity.Subject;
import com.zhou.entity.vo.SubjectQuery;
import com.zhou.mapper.SubjectMapper;
import com.zhou.service.SubjectService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;

import java.util.List;

@Service
public class SubjectServiceImpl extends ServiceImpl<SubjectMapper,Subject>  implements SubjectService {
    @Override
    public void pageQuery(Page<Subject> pageParam, SubjectQuery subjectQuery) {
        QueryWrapper<Subject> queryWrapper=new QueryWrapper<Subject>();
        queryWrapper.orderByAsc("id");
        if (subjectQuery==null){
            baseMapper.selectPage(pageParam,queryWrapper);
            return;
        }
        String getSubjectTypeId=subjectQuery.getSubjectTypeId();

        if (StringUtils.isNotEmpty(getSubjectTypeId)){
            queryWrapper.eq("Subject_type_id",getSubjectTypeId);
        }
        baseMapper.selectPage(pageParam,queryWrapper);
    }

    @Override
    public List<Subject> countSubject() {
        return baseMapper.countSubject();
    }
}
